package cn.edu.hatu.bookshop.service;


import cn.edu.hatu.bookshop.dao.BookMapper;
import cn.edu.hatu.bookshop.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookService  {
    private BookMapper bookMapper;
    @Autowired
    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }
    public List<Book> getAll(){
        List<Book> books = bookMapper.listBooks();
        return books;
    }
    public Book findById(int bookId){
        Book book = bookMapper.findById(bookId);
        return book;
    }
    public int getTableCount(){
        int count = bookMapper.getTableCount();
        return count;
    }
    public List<Book> getBooksByClassifyId(int classifyId){
        List<Book> books = bookMapper.getBooksByClassifyId(classifyId);
        return books;
    }
    public List<Book> fuzzyQuery(String str){
        String regex = "%"+str+"%";
        List<Book> books = bookMapper.fuzzyQuery(regex);
        return books;
    }
    public void addBook(Book book){
        bookMapper.addBook(book);
    }
    public void modifyBook(Book book){
        bookMapper.updateBook(book);
    }
    public void delBookById(int bookId){
        bookMapper.delBookById(bookId);
    }


}
